package com.zpxt.zpxt.serve;

import com.zpxt.zpxt.dao.CompanyRepository;
import com.zpxt.zpxt.dao.TalentRepository;
import com.zpxt.zpxt.entity.Company;
import com.zpxt.zpxt.entity.Talent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author:hjx
 * @Description:
 * @Date: Created in 16:36 2018/4/3
 * @Modified By:
 */
@Service("registerServe")
public class RegisterServe {
    @Autowired
    CompanyRepository companyRepository;
    @Autowired
    TalentRepository talentRepository;

    public void addCompany(Company company) throws Exception {
        //重复验证
        List<Company> list = companyRepository.findByCode(company.getCode());
        if (list.size() > 0){
            throw new Exception("企业账号不能重复！");
        }
        list = companyRepository.findByName(company.getName());
        if (list.size() > 0){
            throw new Exception("企业名称不能重复！");
        }
        list = companyRepository.findByEmail(company.getEmail());
        if (list.size()> 0){
            throw new Exception("企业邮箱不能重复！");
        }
        //增
        companyRepository.save(company);
    }

    public void addTalent(Talent talent) throws Exception {
        //重复验证
        List<Talent> list = talentRepository.findByCode(talent.getCode());
        if (list.size()> 0){
            throw new Exception("求职者账号不能重复！");
        }
        list = talentRepository.findByEmail(talent.getEmail());
        if (list.size()> 0){
            throw new Exception("求职者邮箱不能重复！");
        }
        //增
        talentRepository.save(talent);
    }
}
